package base.aop;

import base.model.Result;
import com.alibaba.fastjson.JSONObject;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;

import java.util.Date;

/**
 * @author GuoFei
 * @date 2018/9/12 17:29
 */
@Aspect
@Component
@Order(8)
public class TryException {

    @Around(value = "pointCut()")
    public Object round(ProceedingJoinPoint jp){
//        Object[] args = jp.getArgs();
//        Object target = jp.getTarget();
//        Signature method = jp.getSignature();
//        String params = "";
//        for (Object arg : args) {
//            if (!ObjectUtils.isEmpty(arg)) {
//                params += arg.toString() + ",";
//            } else {
//                params += "null,";
//            }
//        }
//        String objstr = "";
//        if (!ObjectUtils.isEmpty(target)) {
//            objstr = target.toString();
//        }
        Object result;
        try {
            result = jp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return Result.error();
        }
        return result;
    }

    @Pointcut(value = "execution(* base.service.*.*(..))")
    public void pointCut(){}

}

